load("//bazel:skia_rules.bzl", "exports_files_legacy", "select_multi", "skia_cc_library")

licenses(["notice"])

exports_files_legacy()

skia_cc_library(
    name = "utils",
    testonly = True,
    srcs = [
        "BackendSurfaceFactory.cpp",
        "BackendSurfaceFactory.h",
        "BackendTextureImageFactory.cpp",
        "BackendTextureImageFactory.h",
        "ContextType.cpp",
        "ContextType.h",
        "FenceSync.h",
        "FlushFinishTracker.cpp",
        "FlushFinishTracker.h",
        "GpuTimer.h",
        "GrContextFactory.cpp",
        "GrContextFactory.h",
        "GrTest.cpp",
        "ManagedBackendTexture.cpp",
        "ManagedBackendTexture.h",
        "MemoryCache.cpp",
        "MemoryCache.h",
        "ProtectedUtils.cpp",
        "ProtectedUtils.h",
        "ProxyUtils.cpp",
        "ProxyUtils.h",
        "TestContext.cpp",
        "TestContext.h",
        "TestOps.cpp",
        "TestOps.h",
        "YUVUtils.cpp",
        "YUVUtils.h",
        "//tools/gpu/mock:private_hdrs",
        "//tools/gpu/mock:srcs",
    ] + select_multi({
        "//src/gpu:gl_ganesh": [
            "//tools/gpu/gl:private_hdrs",
            "//tools/gpu/gl:srcs",
        ],
        "//src/gpu:vulkan_ganesh": [
            "//tools/gpu/vk:private_hdrs",
            "//tools/gpu/vk:srcs",
        ],
        "//src/gpu:metal_ganesh": [
            "//tools/gpu/mtl:private_hdrs",
            "//tools/gpu/mtl:srcs",
        ],
        # TODO(kjlubick) Handle other backends
    }),
    hdrs = [
        "GrContextFactory.h",
    ],
    visibility = [
        "//bench:__pkg__",
        "//modules/skottie:__pkg__",
        "//tests:__pkg__",
        "//tools/testrunners/benchmark/target:__pkg__",
        "//tools/testrunners/common/surface_manager:__pkg__",
        "//tools/viewer:__pkg__",
    ],
    deps = ["//:skia_internal"] + select_multi({
        "//src/gpu:gl_ganesh": ["//tools/gpu/gl:deps"],
        "//src/gpu:vulkan_ganesh": ["//tests:test_type"],
    }) + select({
        "@platforms//os:macos": ["//tools:autorelease_pool_objc"],
        "//conditions:default": ["//tools:autorelease_pool"],
    }),
)

skia_cc_library(
    name = "ganesh_gl_utils",
    testonly = True,
    srcs = [
        "BackendSurfaceFactory.cpp",
        "BackendSurfaceFactory.h",
        "BackendTextureImageFactory.cpp",
        "BackendTextureImageFactory.h",
        "ContextType.cpp",
        "ContextType.h",
        "FenceSync.h",
        "FlushFinishTracker.cpp",
        "FlushFinishTracker.h",
        "GpuTimer.h",
        "GrContextFactory.cpp",
        "GrContextFactory.h",
        "GrTest.cpp",
        "ManagedBackendTexture.cpp",
        "ManagedBackendTexture.h",
        "MemoryCache.cpp",
        "MemoryCache.h",
        "ProtectedUtils.cpp",
        "ProtectedUtils.h",
        "ProxyUtils.cpp",
        "ProxyUtils.h",
        "TestContext.cpp",
        "TestContext.h",
        "TestOps.cpp",
        "TestOps.h",
        "//tools/gpu/gl:private_hdrs",
        "//tools/gpu/gl:srcs",
        "//tools/gpu/mock:private_hdrs",
        "//tools/gpu/mock:srcs",
    ],
    hdrs = [
        "GrContextFactory.h",
    ],
    visibility = [
        "//bench:__subpackages__",
        "//tools:__subpackages__",
    ],
    deps = [
        "//:core",
        "//src/base",
        "//src/core:core_priv",
        "//src/gpu/ganesh/gl:ganesh_gl_TEST_UTIL",
        "//tools/gpu/gl:deps",
    ] + select({
        "@platforms//os:macos": ["//tools:autorelease_pool_objc"],
        "//conditions:default": ["//tools:autorelease_pool"],
    }),
)

skia_cc_library(
    name = "ganesh_vulkan_utils",
    testonly = True,
    srcs = [
        "BackendSurfaceFactory.cpp",
        "BackendSurfaceFactory.h",
        "BackendTextureImageFactory.cpp",
        "BackendTextureImageFactory.h",
        "ContextType.cpp",
        "ContextType.h",
        "FenceSync.h",
        "FlushFinishTracker.cpp",
        "FlushFinishTracker.h",
        "GpuTimer.h",
        "GrContextFactory.cpp",
        "GrContextFactory.h",
        "GrTest.cpp",
        "ManagedBackendTexture.cpp",
        "ManagedBackendTexture.h",
        "MemoryCache.cpp",
        "MemoryCache.h",
        "ProtectedUtils.cpp",
        "ProtectedUtils.h",
        "ProxyUtils.cpp",
        "ProxyUtils.h",
        "TestContext.cpp",
        "TestContext.h",
        "TestOps.cpp",
        "TestOps.h",
        "//src/ports:load_dynamic_library",
        "//tools/gpu/mock:private_hdrs",
        "//tools/gpu/mock:srcs",
        "//tools/gpu/vk:private_hdrs",
        "//tools/gpu/vk:srcs",
    ],
    hdrs = [
        "GrContextFactory.h",
    ],
    target_compatible_with = select({
        # We should not be compiling Vulkan tests for macOS.
        "@platforms//os:macos": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
    visibility = [
        "//bench:__subpackages__",
        "//tools:__subpackages__",
    ],
    deps = [
        "//:core",
        "//src/base",
        "//src/core:core_priv",
        "//src/gpu/ganesh/vk:ganesh_vulkan_TEST_UTIL",
        "//tests:test_type",
        "//third_party/vulkanmemoryallocator",
        "//tools:autorelease_pool",
    ],
)
